# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Christoph Haag <christoph.haag@collabora.com>

pkgname=openvr
pkgver=1.23.8
pkgrel=1
pkgdesc="API and runtime that allows access to VR hardware from multiple vendors"
arch=(loong64 x86_64)
url="https://github.com/ValveSoftware/openvr"
license=(custom)
depends=(jsoncpp libgl)
makedepends=(cmake)
source=(${url}/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz
        openvr-fix-vsprintf_s.patch::${url}/pull/594.patch
        openvr-use-system-jsoncpp-1.23.7.patch::${url}/pull/1716.patch)
sha256sums=('4d3b5322777f130b70bcd92ce4cc865ee7066df48fe7407ff9e64e3cfb78c42a'
            '1d954060f27b16485e398654d6730105abc251d372da03fbba38496db17885ae'
            'f79c6edf25efa1aac42b60db48d72f4e3c771039c9cd0fc0870fd51f17712229')

prepare() {
  cd ${pkgname}-${pkgver}
  rm -rf thirdparty/jsoncpp
  patch -p1 < ../openvr-fix-vsprintf_s.patch
  patch -p1 < ../openvr-use-system-jsoncpp-1.23.7.patch
}

build() {
  cmake -B build -S ${pkgname}-${pkgver} \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DBUILD_SHARED=1 \
    -DUSE_SYSTEM_JSONCPP=True
  make -C build
}

package() {
  make -C build DESTDIR="${pkgdir}" install
  install -Dm644 ${pkgname}-${pkgver}/LICENSE -t "${pkgdir}"/usr/share/licenses/${pkgname}
}
